package hw524919.lesson2;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

public class InputCount {
	private String readString;
	private int numCount=0;
	private int charCount=0;
	private int spaceCount=0;
	private int otherCount=0;
	private Map<String,Integer> countResult;
	
	public InputCount(){
		readString();
		countInput();
		mapCountResult();
	}
	
	public Map<String,Integer> getCountResultByMap(){
		return countResult;
	}
	
	private Map<String,Integer> mapCountResult(){
		countResult=new HashMap<String,Integer>();
		countResult.put("numCount", numCount);
		countResult.put("charCount",charCount);
		countResult.put("spaceCount",spaceCount);
		countResult.put("otherCount",otherCount);
		return countResult;
	}
	
	private void readString(){
		BufferedReader bReader=new BufferedReader(new InputStreamReader(System.in));
		try{
			System.out.print("Please input Some:");
			readString=bReader.readLine();
		}catch(Exception e){
			e.printStackTrace();
			readString=null;
		}
	}
	
	private void countInput(){
		if(StringUtils.isEmpty(readString)) return;
		for(char a : readString.toCharArray()){
			if((int)a>='0'&&(int)a<='9'){
				numCount++;
			}else if((a>='a'&&a<='z')||(a>='A'&&a<='Z')){
				charCount++;
			}else if(a==' '){
				spaceCount++;
			}else{
				otherCount++;
			}
		}
	}
}
